package com.cz.run.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.cz.run.beans.mysql.UserTradeRecord;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * 用户交易记录 Mapper 接口
 * </p>
 *
 * @author CAIYJ
 * @since 2018-05-23
 */
@Repository
public interface UserTradeRecordDao extends BaseMapper<UserTradeRecord> {

    @Select("SELECT MAX(point) FROM user_trade_record WHERE type = 5 AND create_time > #{startTime} AND create_time < #{endTime}")
    Double getMaxPointInDay(@Param("startTime") String time,@Param("endTime")String endTime);

    @Select("<script>  " + "SELECT * "
            + "FROM user_trade_record AS a " + "INNER JOIN user_base AS b ON a.user_id = b.id "
            + "<where> ${ew.sqlSegment} </where> </script> ")
    List<UserTradeRecord> getUserTradeRecordByUserNameAndAddress( @Param("ew") Wrapper<UserTradeRecord> wrapper);

    @Select("<script>  " + "SELECT count(0) "
            + "FROM user_trade_record AS a " + "INNER JOIN user_base AS b ON a.user_id = b.id "
            + "<where> ${ew.sqlSegment} </where> </script> ")
    int getCountByUserNameAndAddress( @Param("ew") Wrapper<UserTradeRecord> wrapper);
}
